﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using SellAndBuy.Application.Query.DTOs;
using SellAndBuy.Application.Services;
using SellAndBuy.DistributedServices.IoC;

namespace SellAndBuy.DistributedServices
{
    /// <summary>
    /// Ad Query Service
    /// </summary>
    [UnityInstanceProviderBehavior] //create instance and inject dependencies using unity container
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class AdQueryWebService : IAdQueryWebService
    {
        private readonly IAdQueryService _adQueryService;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="adQueryService">Query application service</param>
        public AdQueryWebService(IAdQueryService adQueryService)
        {
            if (adQueryService == null)
                throw new ArgumentNullException("adQueryService");

            _adQueryService = adQueryService;
        }

        public IList<AdDTO> FindAds()
        {
            return _adQueryService.FindAds().ToList();
        }

        public IList<AdDTO> FindAds(int pageIndex, int pageCount)
        {
            return _adQueryService.FindAds(pageIndex, pageCount).ToList();
        }

        public AdDTO FindAdByID(int id)
        {
            return _adQueryService.FindAdByID(id);
        }
    }
}
